<template>
	<div class="register absolute">
		<picker @change="bindBzChange" :value="bzIndex" :range-key="'DEPARTNAME'" :range="bzArray">
			<view :class="'uni-input language language'+bzIndex"></view>
		</picker>
		<div class="shading">
			<div class="pictrue acea-row row-center-wrapper">
				<image :src="logoUrl" v-if="logoUrl" />
			</div>
		</div>
		<div class="whiteBg" v-if="formItem === 1">
			<div class="title acea-row row-center-wrapper">
				<div class="item" :class="current === index ? 'on' : ''" v-for="(item, index) in navList"
					@click="navTap(index)" :key="index">
					{{ item }}
				</div>
			</div>
			<div class="list" :hidden="current !== 0">
				<form @submit.prevent="submit">
					<div class="item">
						<div class="acea-row row-middle">
							<image src="/static/images/phone_1.png"></image>
							<!-- <image :src="images" style="width: 60rpx;" @click="toggle('bottom')"></image>
							<text @click="toggle('bottom')">{{index}}</text> -->
							<!-- 国旗和区号 -->
							<input :placeholder="$t('tophonenumber3')" type="text" v-model="account" required />
						</div>
					</div>
					<div class="item">
						<div class="acea-row row-middle">
							<image src="/static/images/code_2.png"></image>
							<input :placeholder="$t('Input.password')" type="password" v-model="password" required />
						</div>
					</div>
				</form>

			</div>
			<div class="list" :hidden="current !== 1">
				<div class="item">
					<div class="acea-row row-middle">
						<image src="/static/images/phone_1.png"></image>
						<input :placeholder="$t('Enter.mobile.number')" type="text" v-model="account" />
					</div>
				</div>
				<!-- <div class="item">
					<div class="acea-row row-middle">
						<image src="/static/images/code_2.png"></image>
						<input :placeholder="$t('Verification.Code')" type="text" class="codeIput" v-model="captcha" />
						<button class="code" :disabled="disabled" :class="disabled === true ? 'on' : ''" @click="code">
							{{ text }}
						</button>
					</div>
				</div> -->
				<!-- <div class="item" v-if="isShowCode">
					<div class="acea-row row-middle">
						<image src="/static/images/code_2.png"></image>
						<input :placeholder="$t('Verification.Code')" type="text" class="codeIput" v-model="codeVal" />
						<div class="code" @click="">
							<image class="code-img" :src="codeUrl" />
						</div>
					</div>
				</div> -->
			</div>
			<div class="protocol acea-row row-between-wrapper">
				<checkbox-group class="checkgroup" @change='isAgree=!isAgree'>
					<checkbox class="checkbox" :checked="isAgree ? true : false" />
					<text class="protocol_text">{{$t('I.have.agreed')}}<text @click="showAgreement=true;isAgree=true"
							class="font_pro">{{$t('User.agreement')}}</text></text>

				</checkbox-group>
			</div>
			<div class="logon" @click="loginMobile" :hidden="current !== 1">{{$t('Sign.in')}}</div>
			<div class="logon" @click="submit" :hidden="current === 1">{{$t('Sign.in')}}</div>
			<div class="tip">
				{{$t('No.account')}}
				<span @click="formItem = 2" class="font-color-red">{{$t('Register.now')}}</span>
			</div>
			<!-- #ifdef APP-PLUS -->
			<!-- <view class="appLogin" v-if="!appLoginStatus && !appleLoginStatus">
				<view class="hds">
					<span class="line"></span>
					<p>{{$t('Other.ogins')}}</p>
					<span class="line"></span>
				</view>
				<view class="btn-wrapper">
					<view class="btn wx" @click="wxLogin">
						<span class="iconfont icon-s-weixindenglu1"></span>
					</view>
					<view class="apple-btn" @click="appleLogin" v-if="appleShow">
						<view class="iconfont icon-s-pingguo"></view>{{$t('Apple.login')}}
					</view>
				</view>
			</view> -->
			<!-- #endif -->
		</div>
		<div class="whiteBg" v-else>
			<div class="title">{{$t('Registered.account')}}</div>

			<div class="title acea-row choose">
				<!-- <div class="item" :class="reg_type === 1 ? 'on' : ''" 
					@click="choose_type(1)">
					{{$t('Mobile.registration')}}
				</div> -->
				<div class="item" :class="reg_type === 2 ? 'on' : ''" @click="choose_type(2)">
					{{$t('Email.registration')}}
				</div>
			</div>
			<div class="list">
				<div class="item">
					<div class="acea-row row-middle">
						<image src="/static/images/phone_1.png"></image>
						<input :placeholder="$t('Enter.member.name')" type="text" v-model="nickname" />
					</div>
				</div>
				<div class="item" v-if="reg_type==1">
					<div class="acea-row row-middle">
						<!-- <image src="/static/images/phone_1.png"></image> -->
						<image :src="images" style="width: 60rpx;" @click="toggle('bottom')"></image>
						<text @click="toggle('bottom')">{{index}}</text>
						<!-- 国旗和区号 -->
						<input :placeholder="$t('tophonenumber')" type="text" v-model="account" />
					</div>
				</div>
				<div class="item" v-if="reg_type==2">
					<div class="acea-row row-middle">
						<image src="/static/images/email (1).png"></image>
						<input :placeholder="$t('phonenumber.email')" type="text" v-model="account" />
					</div>
				</div>

				<!-- 填写验证码输入框 -->
				<div class="item" v-if="VerifyCode">
					<div class="acea-row row-middle">
						<image src="/static/images/code_2.png"></image>
						<input type="text" :placeholder="$t('Verification.Code')" class="codeIput" v-model="captcha" />
						<!-- {{$t('store.get.code')}} -->
						<button class="code" :disabled="disabled" :class="disabled === true ? 'on' : ''" @click="code">
							{{btnText}}
						</button>
					</div>
				</div>
				<!-- 填写验证码输入框 -->
				<div class="item">
					<div class="acea-row row-middle">
						<image src="/static/images/code_1.png"></image>
						<input :placeholder="$t('Input.password')" type="password" v-model="password" />
					</div>
				</div>
				<div class="item">
					<div class="acea-row row-middle">
						<image src="/static/images/code_1.png"></image>
						<input :placeholder="$t('2Input.password')" type="password" v-model="repassword" />
					</div>
				</div>
				<div class="item" v-if="isCode">
					<div class="acea-row row-middle">
						<image src="/static/images/code_2.png"></image>
						<input :placeholder="$t('Invitation.code1')" type="text" class="codeIput" v-model="codeVal" />
					</div>
				</div>
			</div>
			<div class="protocol acea-row row-between-wrapper">
				<checkbox-group class="checkgroup" @change='isAgree=!isAgree'>
					<checkbox class="checkbox" :checked="isAgree ? true : false" />
					<text class="protocol_text">{{$t('I.have.agreed')}}<text @click="showAgreement=true;isAgree=true"
							class="font_pro">{{$t('User.agreement')}}</text></text>
				</checkbox-group>
			</div>
			<div class="logon" @click="register">{{$t('register')}}</div>
			<div class="tip">
				{{$t('Existing.account')}}
				<span @click="formItem = 1" class="font-color-red">{{$t('Sign.in.now')}}</span>
			</div>
			<!-- #ifdef APP-PLUS -->
			<!-- <view class="appLogin" v-if="!appLoginStatus && !appleLoginStatus">
				<view class="hds">
					<span class="line"></span>
					<p>{{$t('Other.ogins')}}</p>
					<span class="line"></span>
				</view>
				<view class="btn-wrapper">
					<view class="btn wx" @click="wxLogin">
						<span class="iconfont icon-s-weixindenglu1"></span>
					</view>
					<view class="apple-btn" @click="appleLogin" v-if="appleShow">
						<view class="iconfont icon-s-pingguo"></view>{{$t('Apple.login')}}
					</view>
				</view>
			</view> -->
			<!-- #endif -->
		</div>
		<div class="bottom"></div>
		<view class="settlementAgreement" v-if="showAgreement">
			<view class="setAgCount">
				<i class="icon iconfont icon-cha" @click="showAgreement = false"></i>
				<div class="title">{{$t('User.agreement2')}}</div>
				<view class="content">
					<jyf-parser :html="agreement" ref="article" :tag-style="tagStyle"></jyf-parser>
				</view>
			</view>
		</view>
		<uni-popup ref="popup" background-color="#fff" type="bottom" style="padding: 20rpx;">
			<view style="padding: 10rpx;border-radius: 25px;">
				<text class="bank_name" v-for="(item, index) in contry" @click="select(item.index,item.img,item.name)"
					:key="index">
					<image :src="item.img" style="width: 60rpx;height: 30rpx; bottom: -6rpx;margin-right: 10rpx;">
					</image>{{item.name}}
				</text>
			</view>
		</uni-popup>
	</div>

</template>
<script>
	// +----------------------------------------------------------------------
	// | CRMEB [ CRMEB赋能开发者，助力企業发展 ]
	// +----------------------------------------------------------------------
	// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
	// +----------------------------------------------------------------------
	// | Licensed CRMEB並不是自由软件，未经许可不能去掉CRMEB相關版权
	// +----------------------------------------------------------------------
	// | Author: CRMEB Team <admin@crmeb.com>
	// +----------------------------------------------------------------------
	import dayjs from "@/plugin/dayjs/dayjs.min.js";
	import sendVerifyCode from "@/mixins/SendVerifyCode";
	import {
		loginH5,
		loginMobile,
		registerVerify,
		register,
		getCodeApi,
		getUserInfo,
		getCaptcha,
		getAgreementApi,
		appleLogin
	} from "@/api/user";
	// #ifdef APP-PLUS
	import {
		wechatAppAuth,
		appleAppAuth
	} from '@/api/api.js'
	// #endif
	import attrs, {
		required,
		alpha_num,
		chs_phone
	} from "@/utils/validate";
	import {
		validatorDefaultCatch
	} from "@/utils/dialog";
	import {
		getLogo,
		getconfig
	} from "@/api/public";
	// import cookie from "@/utils/store/cookie";
	import {
		VUE_APP_API_URL
	} from "@/utils";
	import parser from "@/components/jyf-parser/jyf-parser";

	const BACK_URL = "login_back_url";

	export default {
		name: "Login",
		mixins: [sendVerifyCode],
		components: {
			"jyf-parser": parser
		},
		data: function() {
			return {
				btnState: true,
				btnText: "发送验证码",
				navList: [this.$t("Account.login")],
				current: 0,
				account: "",
				nickname: "",
				password: "",
				repassword: "",
				index: '+852',
				images: '/static/images/hk.png',
				captcha: "",
				formItem: 1,
				type: "login",
				logoUrl: "",
				keyCode: "",
				codeUrl: "",
				smscodeVal: "",
				codeVal: "",
				isShowCode: false,
				isCode: false,
				VerifyCode: false,
				showAgreement: false,
				contry: [{
						'index': '+852',
						'img': '/static/images/hk.png',
						'name': '中國香港'
					},
					{
						'index': '+850',
						'img': '/static/images/cx.png',
						'name': '조선'
					},
					{
						'index': '+670',
						'img': '/static/images/ddw.png',
						'name': 'Timor-Leste'
					},
					{
						'index': '+63',
						'img': '/static/images/flb.png',
						'name': 'Philippines'
					},
					{
						'index': '+82',
						'img': '/static/images/hg.png',
						'name': '한국'
					},
					{
						'index': '+855',
						'img': '/static/images/jpz.png',
						'name': 'Cambodia'
					},
					{
						'index': '+856',
						'img': '/static/images/lw.png',
						'name': 'Laos'
					},
					{
						'index': '+60',
						'img': '/static/images/mlxy.png',
						'name': 'Malaysia'
					},
					{
						'index': '+95',
						'img': '/static/images/md.png',
						'name': 'Myanmar'
					},
					{
						'index': '+81',
						'img': '/static/images/rb.png',
						'name': 'Japan'
					},
					{
						'index': '+66',
						'img': '/static/images/tg.png',
						'name': 'ประเทศไทย'
					},
					{
						'index': '+673',
						'img': '/static/images/wl.png',
						'name': 'Brunei'
					},
					{
						'index': '+65',
						'img': '/static/images/xjb.png',
						'name': 'Singapore'
					},
					{
						'index': '+62',
						'img': '/static/images/ydnxy.png',
						'name': 'Indonesia'
					},
					{
						'index': '+84',
						'img': '/static/images/yn.png',
						'name': 'Việt Nam'
					},
					{
						'index': '+86',
						'img': '/static/images/gq1.png',
						'name': '中国'
					},
					{
						'index': '+1',
						'img': '/static/images/mg.png',
						'name': 'U.S.A'
					},
					{
						'index': '+61',
						'img': '/static/images/adly.png',
						'name': 'Australia'
					},
					{
						'index': '+1',
						'img': '/static/images/jnd.png',
						'name': 'Canada'
					},
					{
						'index': '+886',
						'img': '/static/images/tw.png',
						'name': '中國臺灣'
					}
				],
				tagStyle: {
					img: 'width:100%;display:block;'
				},
				isAgree: false,
				agreement: '',
				appLoginStatus: false, // 微信登錄强制绑定手機號碼状态
				appUserInfo: null, // 微信登錄保存的用户資訊
				appleLoginStatus: false, // 苹果登錄强制绑定手機號碼状态
				appleUserInfo: null,
				appleShow: false, // 苹果登錄版本必须要求ios13以上的
				keyLock: true,
				// 初始化一个默认空值，防止报错
				bzArray: [],
				// 当前选中的下标，触发change事件后需要跟着变
				bzIndex: 0,
				reg_type: 2,
			};
		},
		watch: {
			formItem: function(nval, oVal) {
				if (nval == 1) {
					this.type = 'login'
				} else {
					this.type = 'register'
				}
			}
		},
		onLoad() {
			let self = this
			uni.getSystemInfo({
				success: function(res) {
					if (res.platform.toLowerCase() == 'ios' && self.getSystem(res.system) >= 13) {
						self.appleShow = true
					}
				}
			});

			this.bzArray = [{
				DEPARTNAME: this.$t('index.lang.en')
			}, {
				DEPARTNAME: this.$t('index.lang.zh-Hant')
			}, {
				DEPARTNAME: this.$t('index.lang.zh-Hans')
			}, {
				DEPARTNAME: this.$t('index.lang.ja')
			}, {
				DEPARTNAME: this.$t('index.lang.th')
			}, {
				DEPARTNAME: this.$t('index.lang.vi')
			}, {
				DEPARTNAME: this.$t('index.lang.id')
			}, {
				DEPARTNAME: this.$t('index.lang.hi')
			}, {
				DEPARTNAME: this.$t('index.lang.tr')
			}, {
				DEPARTNAME: this.$t('index.lang.ar')
			}, {
				DEPARTNAME: this.$t('index.lang.ko')
			}];
			//this.$i18n.locale = 'zh-Hans'
			//uni.setStorageSync('lang', 'zh');
			//,{DEPARTNAME:this.$t('index.lang.vi')},{DEPARTNAME:this.$t('index.lang.id')},{DEPARTNAME:this.$t('index.lang.hi')},{DEPARTNAME:this.$t('index.lang.tr')},{DEPARTNAME:this.$t('index.lang.ar')}

			if (uni.getLocale() == 'en') this.bzIndex = 0
			if (uni.getLocale() == 'zh-Hans') this.bzIndex = 1
			if (uni.getLocale() == 'zh-Hant') this.bzIndex = 2
			if (uni.getLocale() == 'ja') this.bzIndex = 3
			if (uni.getLocale() == 'th') this.bzIndex = 4
			if (uni.getLocale() == 'vi') this.bzIndex = 5
			if (uni.getLocale() == 'id') this.bzIndex = 6
			if (uni.getLocale() == 'hi') this.bzIndex = 7
			if (uni.getLocale() == 'tr') this.bzIndex = 8
			if (uni.getLocale() == 'ar') this.bzIndex = 9
			if (uni.getLocale() == 'ko') this.bzIndex = 10
		},
		mounted: function() {
			const app = getApp();
			console.log(app.globalData);
			this.$nextTick(() => {
				this.logoUrl = app.globalData.login_logo
				if (app.globalData.required_invitation_code == 1) this.isCode = true
				if (app.globalData.required_verify_code == 1) this.VerifyCode = true
				this.getAgreement();
			});
			uni.$on('update', (data) => {
				if (data.required_invitation_code == 1) this.isCode = true
				if (data.required_verify_code == 1) this.VerifyCode = true
				this.logoUrl = data.login_logo
			})
		},
		onReady() {
			// #ifdef APP-PLUS
			const app = getApp();
			this.logoUrl = app.globalData.login_logo
			// #endif
		},
		methods: {

			bindBzChange: function(e) {
				if (e.target.value == 0) {
					uni.setLocale('en');
					this.$i18n.locale = 'en'
				}
				if (e.target.value == 1) {
					uni.setLocale('zh-Hans');
					this.$i18n.locale = 'zh-Hans'
				}
				if (e.target.value == 2) {
					uni.setLocale('zh-Hant');
					this.$i18n.locale = 'zh-Hant'
				}
				if (e.target.value == 3) {
					uni.setLocale('ja');
					this.$i18n.locale = 'ja'
				}
				if (e.target.value == 4) {
					uni.setLocale('th');
					this.$i18n.locale = 'th'
				}
				if (e.target.value == 5) {
					uni.setLocale('vi');
					this.$i18n.locale = 'vi'
				}
				if (e.target.value == 6) {
					uni.setLocale('id');
					this.$i18n.locale = 'id'
				}
				if (e.target.value == 7) {
					uni.setLocale('hi');
					this.$i18n.locale = 'hi'
				}
				if (e.target.value == 8) {
					uni.setLocale('tr');
					this.$i18n.locale = 'tr'
				}
				if (e.target.value == 9) {
					uni.setLocale('ar');
					this.$i18n.locale = 'ar'
				}
				if (e.target.value == 10) {
					uni.setLocale('ko');
					this.$i18n.locale = 'ko'
				}
				//uni.setStorageSync('bzIndex',e.target.value)
				// location.reload()
				console.log('picker发送选择改变，携带值为', e.target.value)
				this.bzIndex = e.target.value;
				this.currentDepartId = this.bzArray[this.bzIndex].ORG_CODE;
			},
			select(index, img) {
				this.images = img
				this.index = index
				this.$refs.popup.close()
			},
			toggle(type) {
				this.type = type
				// open 方法傳入参数 等同在 uni-popup 组件上绑定 type属性
				this.$refs.popup.open(type)
			},
			getSystem(system) {
				if (system.indexOf('iOS') === -1) {
					return system
				} else {
					let str = system.split(' ')[1]
					if (str.indexOf('.')) {
						return Number(str.split('.')[0])
					} else {
						return Number(str)
					}
				}

			},
			// 苹果登錄
			appleLogin() {
				let self = this
				this.account = ''
				this.captcha = ''
				uni.showLoading({
					title: this.$t("Logging.in")
				})

				uni.login({
					provider: 'apple',
					timeout: 10000,
					success(loginRes) {
						uni.getUserInfo({
							provider: 'apple',
							success: function(infoRes) {
								self.appleUserInfo = infoRes.userInfo
								self.appleLoginApi()
							},
							fail() {
								uni.showToast({
									title: 'Failed to get user information',
									icon: 'none',
									duration: 2000
								})
							},
							complete() {
								uni.hideLoading()
							}
						});
					},
					fail(error) {
						console.log(error)
					}
				})
			},
			// 苹果登錄Api
			appleLoginApi() {
				let that = this
				appleAppAuth({
					openId: that.appleUserInfo.openId,
					nickname: (that.appleUserInfo.fullName.familyName || '') + (that.appleUserInfo.fullName
						.giveName || ''),
				}).then(({
					data
				}) => {
					const backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
					that.$Cache.clear(BACK_URL);
					that.$store.commit("LOGIN", {
						'token': data.token,
						'time': data.exp
					});
					that.$store.commit("SETUID", data.user.uid);
					that.$store.commit('UPDATE_USERINFO', data.user);

					let method
					let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart',
						'/pages/goods_cate/goods_cate',
						'/pages/user/index'
					]
					if (indexPat.includes(this.getPath(backUrl))) {
						method = 'switchTab'
					} else {
						method = 'navigateTo'
					}
					if (this.getPath(backUrl) === '/pages/users/login/index') {
						uni.switchTab({
							url: '/pages/index/index'
						});
						return
					}
					uni[method]({
						url: backUrl
					});
				}).catch(error => {
					uni.showModal({
						title: 'Tips',
						content: `Error information${error}`,
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				})
			},
			// App微信登錄
			wxLogin() {
				let self = this
				this.account = ''
				this.captcha = ''
				uni.showLoading({
					title: this.$t("Logging.in")
				})
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						// 获取用户資訊
						uni.getUserInfo({
							provider: 'weixin',
							success: function(infoRes) {
								self.appUserInfo = infoRes.userInfo
								self.wxLoginApi()
							},
							fail() {
								uni.showToast({
									title: 'Failed to get user information',
									icon: 'none',
									duration: 2000
								})
							},
							complete() {
								uni.hideLoading()
							}
						});
					},
					fail(error) {
						uni.showToast({
							title: this.$t("Login.failed"),
							icon: 'none',
							duration: 2000
						})
					}
				});
			},
			getPath(url) {
				if (url.indexOf("?") != -1) {
					url = url.split("?")[0];
					console.log(url);
				}
				return url
			},
			wxLoginApi() {
				let that = this
				wechatAppAuth({
					userInfo: that.appUserInfo,
					phone: this.account,
					code: this.captcha
				}).then(({
					data
				}) => {
					const backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
					that.$Cache.clear(BACK_URL);
					that.$store.commit("LOGIN", {
						'token': data.token,
						'time': data.exp
					});
					that.$store.commit("SETUID", data.user.uid);
					that.$store.commit('UPDATE_USERINFO', data.user);

					let method
					let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart',
						'/pages/goods_cate/goods_cate',
						'/pages/user/index'
					]
					if (indexPat.includes(this.getPath(backUrl))) {
						method = 'switchTab'
					} else {
						method = 'navigateTo'
					}
					if (this.getPath(backUrl) === '/pages/users/login/index') {
						uni.switchTab({
							url: '/pages/index/index'
						});
						return
					}
					uni[method]({
						url: backUrl
					});
				}).catch(error => {
					uni.showModal({
						title: 'Tips',
						content: `Error information${error}`,
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				})
			},
			getAgreement() {
				let that = this
				getAgreementApi('sys_user_agree').then(res => {
					that.agreement = res.data.sys_user_agree
				})
			},
			getCode() {
				let that = this
				getCodeApi()
					.then(res => {
						that.keyCode = res.data.key;
					})
					.catch(res => {
						that.$util.Tips({
							title: res
						});
					});
			},

			async getLogoImage() {
				let that = this;
				getLogo(2).then(res => {
					that.logoUrl = res.data.logo_url;
				});
			},
			async loginMobile() {
				let that = this;
				if (!that.account) return that.$util.Tips({
					title: this.$t("phonenumber.email2")
				});
				if (!/^[0-9A-Za-z@+*._\s]{4,30}$/i.test(that.account)) return that.$util.Tips({
					title: this.$t("phonenumber.email3")
				});
				// if (!/^[0-9+*\s]{4,26}$/i.test(that.account)) return that.$util.Tips({
				// 	title: '請輸入正确的手機號碼'
				// });
				// if (!/^[0-9]\d{4,17}$/i.test(that.account)) return that.$util.Tips({
				// 	title: '請輸入正确的手機號碼'
				// });
				if (!that.captcha) return that.$util.Tips({
					title: '请输入验证码'
				});
				//if (!/^[\w\d]+$/i.test(that.captcha)) return that.$util.Tips({
				//title: '請輸入正确的驗證碼'
				//});
				if (!that.isAgree) return that.$util.Tips({
					title: this.$t("User.agreement3")
				});
				loginMobile({
						phone: that.account,
						sms_code: that.captcha,
						spread: that.$Cache.get("spread")
					})
					.then(({
						data
					}) => {
						const backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
						that.$Cache.clear(BACK_URL);
						that.$store.commit("LOGIN", {
							'token': data.token,
							'time': data.exp
						});
						that.$store.commit("SETUID", data.user.uid);
						that.$store.commit('UPDATE_USERINFO', data.user);

						let method
						let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart',
							'/pages/goods_cate/goods_cate',
							'/pages/user/index'
						]
						if (indexPat.includes(this.getPath(backUrl))) {
							method = 'switchTab'
						} else {
							method = 'navigateTo'
						}
						if (this.getPath(backUrl) === '/pages/users/login/index') {
							uni.switchTab({
								url: '/pages/index/index'
							});
							return
						}
						uni[method]({
							url: backUrl
						});
					})
					.catch(res => {
						that.$util.Tips({
							title: res
						});
					});
			},
			async register() {
				let that = this;
				if (!that.nickname) return that.$util.Tips({
					title: this.$t("Enter.member.name2")
				});
				if (!that.account) return that.$util.Tips({
					title: this.$t("phonenumber.email2")
				});
				if (!/^[0-9A-Za-z@+*._\s]{4,30}$/i.test(that.account)) return that.$util.Tips({
					title: this.$t("phonenumber.email3")
				});
				// if (!/^[0-9+*\s]{4,26}$/i.test(that.account)) return that.$util.Tips({
				// 	title: '請輸入正确的手機號碼'
				// });
				console.log(that.isCode)
				if (!that.codeVal && that.isCode) return that.$util.Tips({
					title: this.$t("Invitation.code12")
				});
				if (that.index == '' || that.index === undefined) return that.$util.Tips({
					title: this.$t("Number.region")
				});
				/*
				if (!that.captcha) return that.$util.Tips({
					title: '請輸入驗證碼'
				});
				if (!/^[\w\d]+$/i.test(that.captcha)) return that.$util.Tips({
					title: '請輸入正确的驗證碼'
				});*/

				if (!that.captcha && that.VerifyCode) return that.$util.Tips({
					title: this.$t("Verification.Code")
				});
				// 填写验证码的提示
				if (!that.password) return that.$util.Tips({
					title: this.$t("Input.password2")
				});
				if (!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/i.test(that.password)) return that.$util.Tips({
					title: this.$t("Input.password3")
				});
				if (!that.repassword) return that.$util.Tips({
					title: this.$t("2Input.password")
				});
				if (that.password != that.repassword) return that.$util.Tips({
					title: this.$t("notPass")
				});
				if (!that.isAgree) return that.$util.Tips({
					title: this.$t("User.agreement3")
				});
				register({
						nickname: that.nickname,
						phone: that.account,
						invitation_code: that.codeVal,
						sms_code: that.captcha,
						pwd: that.password,
						country_code: that.index,
						spread: that.$Cache.get("spread")
					})
					.then(res => {
						const backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
						that.$Cache.clear(BACK_URL);
						that.$store.commit("LOGIN", {
							'token': res.data.token,
							'time': res.data.exp
						});
						that.$store.commit("SETUID", res.data.user.uid);
						that.$store.commit('UPDATE_USERINFO', res.data.user);
						uni.switchTab({
							url: '/pages/user/index'
						})
					})
					.catch(res => {
						that.$util.Tips({
							title: res
						});
					});
			},
			async code() {
				let that = this;
				if (!that.account) return that.$util.Tips({
					title: this.$t("tophonenumber2")
				});
				if (that.reg_type == 2 && !/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/i.test(that
						.account)) return that.$util.Tips({
					title: this.$t("enter.noemail")
				});
				if (!this.btnState) return false
				this.btnState = false
				let num = 60
				let timer = setInterval(() => {
					if (num <= 0) {
						this.btnState = true
						num = 60
						this.btnText = '发送验证码'
						clearInterval(timer)
						return false
					}
					num--
					this.btnText = `${num}s后重试`
				}, 1000)

				// if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
				// 	title: '請輸入正确的手機號碼'
				// });
				// if (that.formItem == 2) that.type = "register";
				await registerVerify({
						phone: that.account,
						type: 'login',
						key: that.keyCode,
						code: that.codeVal,
						precode: that.index,
						verify_type: that.reg_type,
						lang: uni.getLocale()
					})
					.then(res => {
						that.$util.Tips({
							title: res.message
						});
						// that.sendCode();
					})
					.catch(res => {
						console.log(res, 'res22222222')
						// that.getcaptcha();
						this.btnState = true
						num = 60
						this.btnText = '发送验证码'
						clearInterval(timer)
						that.$util.Tips({
							title: res
						});
					});
			},
			getcaptcha() {
				let that = this
				getCaptcha().then(data => {
					// that.codeUrl = `${VUE_APP_API_URL}/sms_captcha?key=${that.keyCode}`;
					that.codeUrl = data.data.captcha;
				})
				that.isShowCode = true;
			},
			navTap: function(index) {
				this.current = index;
			},
			choose_type: function(index) {
				this.reg_type = index;
			},
			getPath(url) {
				if (url.indexOf("?") != -1) {
					url = url.split("?")[0];
					console.log(url);
				}
				return url
			},
			async submit() {
				let that = this;
				if (!that.account) return that.$util.Tips({
					title: this.$t("phonenumber.email2")
				});
				if (!/^[0-9A-Za-z@+*._\s]{4,30}$/i.test(that.account)) return that.$util.Tips({
					title: this.$t("phonenumber.email3")
				});
				// if (!/^[0-9+*\s]{4,26}$/i.test(that.account)) return that.$util.Tips({
				// 	title: this.$t("phonenumber.email3")
				// });
				// if (!that.codeVal) return that.$util.Tips({
				// 	title: this.$t("Verification.Code22")
				// });
				if (!that.password) return that.$util.Tips({
					title: this.$t("Input.password2")
				});
				if (!that.isAgree) return that.$util.Tips({
					title: this.$t("User.agreement3")
				});

				let info = {
					phone: this.account,
					password: this.password
				}

				this.setUserinfo(info);
				loginH5({
						account: that.account,
						password: that.password,
						spread: that.$Cache.get("spread")
					})
					.then(({
						data
					}) => {
						if (!data.token) {
							uni.showModal({
								title: "提示",
								content: "登录失败"
							})
							return
						}
						console.log(data.token)
						const backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
						that.$Cache.clear(BACK_URL);
						that.$store.commit("LOGIN", {
							'token': data.token,
							'time': data.exp
						});


						that.$store.commit("SETUID", data.user.uid);
						that.$store.commit('UPDATE_USERINFO', data.user);

						let method
						let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart',
							'/pages/goods_cate/goods_cate',
							'/pages/user/index'
						]
						if (indexPat.includes(this.getPath(backUrl))) {
							method = 'switchTab'
						} else {
							method = 'navigateTo'
						}
						// if (this.getPath(backUrl) === '/pages/users/login/index') {
						// 	uni.switchTab({
						// 		url: '/pages/index/index'
						// 	});
						// 	return
						// }
						// uni[method]({
						// 	url: backUrl
						// });
						uni.reLaunch({
							url: '/pages/index/index'
						});
					})
					.catch(e => {
						that.$util.Tips({
							title: e
						});
					});
			},


			setUserinfo(info) {
				this.$store.commit("USER_INFO_U", info);
			}
		}
	};
</script>
<style lang="scss">
	.code img {
		width: 100%;
		height: 100%;
	}

	.choose {
		font-size: 14px !important;
		margin-top: 20rpx;
	}

	.bank_name {
		width: 100%;
		margin-bottom: 20rpx;
		float: left;
	}

	.acea-row.row-middle {
		input {
			margin-left: 20rpx;
		}
	}

	.settlementAgreement {
		width: 100%;
		height: 100%;
		position: fixed;
		top: 0;
		left: 0;
		background: rgba(0, 0, 0, .5);
		z-index: 10;
	}

	.protocol_text {
		color: #999;
	}

	.settlementAgreement .setAgCount {
		background: #fff;
		width: 656rpx;
		height: 458px;
		position: absolute;
		top: 50%;
		left: 50%;
		border-radius: 12rpx;
		-webkit-border-radius: 12rpx;
		padding: 52rpx;
		-webkit-transform: translate(-50%, -50%);
		-moz-transform: translate(-50%, -50%);
		transform: translate(-50%, -50%);
		overflow: hidden;

		.content {
			height: 900rpx;
			overflow-y: scroll;

			::v-deep p {
				font-size: 13px;
				line-height: 22px;
			}

			::v-deep img {
				max-width: 100%;
			}
		}
	}

	.settlementAgreement .setAgCount .icon {
		font-size: 42rpx;
		color: #b4b1b4;
		position: absolute;
		top: 15rpx;
		right: 15rpx;

	}

	.settlementAgreement .setAgCount .title {
		color: #333;
		font-size: 32rpx;
		text-align: center;
		font-weight: bold;
	}

	.settlementAgreement .setAgCount .content {
		margin-top: 32rpx;
		color: #333;
		font-size: 26rpx;
		line-height: 22px;
		text-align: justify;
		text-justify: distribute-all-lines;
		height: 756rpx;
		overflow-y: scroll;
	}

	.protocol {
		margin-top: 30rpx;
	}

	.protocol_text {
		.font_pro {
			color: #5555ff;
		}
	}

	.appLogin {
		.hds {
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 24rpx;
			color: #B4B4B4;

			.line {
				width: 68rpx;
				height: 1rpx;
				background: #CCCCCC;
			}

			p {
				margin: 0 20rpx;
			}
		}

		.btn-wrapper {
			display: flex;
			align-items: center;
			justify-content: center;
			margin-top: 30rpx;

			.btn {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 68rpx;
				height: 68rpx;
				border-radius: 50%;
			}

			.apple-btn {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 246rpx;
				height: 66rpx;
				margin-left: 10rpx;
				background: #EAEAEA;
				border-radius: 34rpx;
				font-size: 24rpx;

				.icon-s-pingguo {
					color: #333;
					margin-right: 10rpx;
					font-size: 34rpx;
				}
			}

			.iconfont {
				font-size: 40rpx;
				color: #fff;
			}

			.wx {
				margin-right: 30rpx;
				background-color: #61C64F;
			}

			.mima {
				background-color: #28B3E9;
			}

			.yanzheng {
				background-color: #F89C23;
			}

		}
	}

	.code img {
		width: 100%;
		height: 100%;
	}

	.acea-row.row-middle {
		input {
			margin-left: 20rpx;
			display: block;
		}
	}

	.login-wrapper {
		padding: 30rpx;

		.shading {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;

			/* #ifdef APP-VUE */
			margin-top: 50rpx;
			/* #endif */
			/* #ifndef APP-VUE */

			margin-top: 200rpx;
			/* #endif */


			image {
				width: 180rpx;
				height: 180rpx;
			}
		}

		.whiteBg {
			margin-top: 100rpx;

			.list {
				border-radius: 16rpx;
				overflow: hidden;

				.item {
					border-bottom: 1px solid #F0F0F0;
					background: #fff;

					.row-middle {
						position: relative;
						padding: 16rpx 45rpx;

						input {
							flex: 1;
							font-size: 28rpx;
							height: 80rpx;
						}

						.code {
							position: absolute;
							right: 30rpx;
							top: 50%;
							color: #E93323;
							font-size: 26rpx;
							transform: translateY(-50%);
						}
					}
				}
			}

			.logon {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 100%;
				height: 86rpx;
				margin-top: 80rpx;
				background-color: $theme-color;
				border-radius: 120rpx;
				color: #FFFFFF;
				font-size: 30rpx;
			}

			.tips {
				margin: 30rpx;
				text-align: center;
				color: #999;
			}
		}
	}

	.language {
		height: 26px;
		line-height: 26px;
		float: right;
		padding: 9px 14px 0 14px;
	}

	.language:before {
		content: '';
		width: 26px;
		height: 26px;
		float: left;
		display: inline-block;
	}

	.language0:before {
		background: url(/static/images/en_us.png) no-repeat;
		background-size: 100%;
	}

	.language1:before {
		background: url(/static/images/zh_cn.png) no-repeat;
		background-size: 100%;
	}

	.language2:before {
		background: url(/static/images/zh_hk.png) no-repeat;
		background-size: 100%;
	}

	.language3:before {
		background: url(/static/images/rb.png) no-repeat;
		background-size: 100%;
	}

	.language4:before {
		background: url(/static/images/th.png) no-repeat;
		background-size: 100%;
	}

	.language5:before {
		background: url(/static/images/vi.png) no-repeat;
		background-size: 100%;
	}

	.language6:before {
		background: url(/static/images/id.png) no-repeat;
		background-size: 100%;
	}

	.language7:before {
		background: url(/static/images/hi.png) no-repeat;
		background-size: 100%;
	}

	.language8:before {
		background: url(/static/images/tr.png) no-repeat;
		background-size: 100%;
	}

	.language9:before {
		background: url(/static/images/ar.png) no-repeat;
		background-size: 100%;
	}

	.language10:before {
		background: url(/static/images/ko.png) no-repeat;
		background-size: 100%;
	}
</style>